﻿@model EquipmentStockInModel
@using Nop.Web.Framework.Localization

@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)

<script>
    $(document).ready(function () {
        bindBootstrapTabSelectEvent('category-edit');
    });
</script>

<style type="text/css">
    .content {
        min-height: auto;
    }
</style>

<div class="content">
    <div class="form-horizontal">
        <div class="row">
            <div class="col-md-12 clearfix">
                <div class="pull-left">
                    @Html.Action("Mode", "Setting", new { modeName = "category-advanced-mode" })
                </div>
            </div>
        </div>
        <div id="category-edit" class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                @Html.RenderBootstrapTabHeader("tab-info", new LocalizedString("基本信息"), true)
            </ul>
            <div class="tab-content">
                @Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
            </div>
        </div>
    </div>
</div>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "category-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab name*@
<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">

@helper TabInfo()
{
    <div class="content" style="padding-bottom:0;">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="form-group">
                            <div class="col-md-3">
                                编号：         @Model.SNo
                            </div>
                            <div class="col-md-3">
                                部门：      @Model.DepartmentName
                            </div>
                            <div class="col-md-3">
                                人员：      @Model.CustomerName
                            </div>
                            <div class="col-md-3">
                                创建时间：      @Model.CreatedOn.ToString("yyyy-MM-dd HH:mm:ss")
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                审核人：         @Model.Reviewer
                            </div>
                            <div class="col-md-3">
                                审核时间：      @(Model.ReviewOn.HasValue?Model.ReviewOn.Value.ToString("yyyy-MM-dd HH:mm:ss"):"")
                            </div>
                            <div class="col-md-3">
                                入库人：      @Model.Keeper
                            </div>
                            <div class="col-md-3">
                                入库时间：      @(Model.KeeperOn.HasValue?Model.KeeperOn.Value.ToString("yyyy-MM-dd HH:mm:ss"):"")
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="content" style="padding-top:0;">
        <div class="form-horizontal">
            <div class="panel-group">
                @if (Model.Id > 0)
                {
                    <div class="content-header clearfix" style="padding-top:0;">
                        <h1 class="pull-left">
                            明细
                        </h1>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-body">
                            @{
                                var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
                                var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
                            }


                            <div id="products-grid"></div>

                            <script>
                                $(document).ready(function() {
                                $("#products-grid").kendoGrid({
                                    dataSource: {
                                        type: "json",
                                        transport: {
                                            read: {
                                                url: "@Html.Raw(Url.Action("Details", "EquipmentStockIn", new { inId = Model.Id}))",
                                                type: "POST",
                                                dataType: "json",
                                                data: addAntiForgeryToken
                                            }
                                        },
                                        schema: {
                                            data: "Data",
                                            total: "Total",
                                            errors: "Errors",
                                            model: {
                                                id: "Id",
                                                fields: {
                                                    EquipmentName: { editable: false, type: "string" },
                                                    Manufacturer: { editable: false, type: "string" },
                                                    Specification: { editable: false, type: "string" },
                                                    Technician: { editable: true, type: "string" },
                                                    TechnicianContact: { editable: true, type: "string" },
                                                    Price: { editable: true, type: "number" },
                                                    Amount: { editable: true, type: "number" },
                                                    Id: { editable: false, type: "number" }
                                                }
                                            }
                                        },
                                        requestEnd: function(e) {
                                            if (e.type == "update") {
                                                this.read();
                                            }
                                        },
                                        error: function(e) {
                                            display_kendoui_grid_error(e);
                                            // Cancel the changes
                                            this.cancelChanges();
                                        },
                                        pageSize: @(defaultGridPageSize),
                                        serverPaging: true,
                                        serverFiltering: true,
                                        serverSorting: true
                                    },
                                    pageable: {
                                        refresh: true,
                                        pageSizes: [@(gridPageSizes)],
                                        @Html.Partial("_GridPagerMessages")
                                    },
                                    editable: {
                                        confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                        mode: "inline"
                                    },
                                    scrollable: false,
                                    columns: [
                                        {
                                            field: "Name",
                                            title: "名称",
                                            width: 300,
                                            headerAttributes: { style: "text-align:center" },
                                        }, {
                                            field: "Manufacturer",
                                            title: "品牌",
                                            width: 200,
                                            headerAttributes: { style: "text-align:center" },
                                        }, {
                                            field: "Specification",
                                            title: "规格型号",
                                            width: 300,
                                            headerAttributes: { style: "text-align:center" },
                                        },{
                                            field: "Price",
                                            title: "价格",
                                            width: 100,
                                            headerAttributes: { style: "text-align:center" },
                                            attributes: { style: "text-align:right" },
                                            editor: function (container, options) {
                                                $('<input name="' + options.field + '"/>')
                                                    .appendTo(container)
                                                    .kendoNumericTextBox({
                                                        format: "{0:n2}",
                                                        decimals: 2
                                                    });
                                            }
                                        }, {
                                            field: "Amount",
                                            title: "数量",
                                            width: 100,
                                            headerAttributes: { style: "text-align:center" },
                                            attributes: { style: "text-align:right" },
                                            editor: function (container, options) {
                                                $('<input name="' + options.field + '"/>')
                                                    .appendTo(container)
                                                    .kendoNumericTextBox({
                                                        format: "{0:n2}",
                                                        decimals: 0
                                                    });
                                            }
                                        }
                                    ]
                                });
                                $('#btnRefreshEquipments').click(function () {
                                    //refresh grid
                                    var grid = $("#products-grid").data('kendoGrid');
                                    grid.dataSource.read();

                                    //return false to don't reload a page
                                    return false;
                                });
                            });
                            </script>
                        </div>
                    </div>
                }
                else
                {
                    <div class="panel panel-default">
                        <div class="panel-body">
                            @T("Admin.Catalog.Categories.Products.SaveBeforeEdit")
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
}
